#include "UDPHandler.h"
#include "FormatMessage.h"
#include "MessageQueue.h"
#include <memory>
#include <cstring>
#include <thread>

#include "Logger.h"
#include "DataParser.h"

std::shared_ptr<CFormatMassage> CUDPHandler::getFormatData(const CMessage& message)
{
	std::cout << "in UDPHandler getData ... " << std::this_thread::get_id() << std::endl;
	LOGDEBUG("in UDPHandler getData ... ");

	if (message.m_length <= 0)
	{
		if (message.m_buff)
		{
			free(message.m_buff);
		}
		std::cout << "CUDPHandler::getData - no data" << std::endl;
		LOGINFO("CUDPHandler::getData - no data");
		return std::shared_ptr<CFormatMassage>(nullptr);
	}

	int data_length = message.m_length + 10;
	char* data = new char[data_length];
	memset(data, 0, data_length);
	memcpy(data, message.m_buff, message.m_length);
	//std::cout << str << std::endl;
	//pFormatMessage->rawData(std::shared_ptr<char>(data)); 
	
	free(message.m_buff);
	CDataParser dataparse;
	return dataparse(std::shared_ptr<char>(data));
}
